#include <algorithm>
#include <cstdio>
#define N 101
using namespace std;
int n, m, ans, t;
int map[N][N];

bool check_line(int x) {
	return !((x << 1) & x || (x >> 1) & x);
}
bool check_next_line(int x, int y) {
	return !(x & y) && !((x << 1) & y) && !((x >> 1) & y);
}
int tot(int x, int row) {
 	int res = 0;
	for (int i = 0; i < m; ++i) {
		res += ((x >> i) & 1) * map[row][i + 1];
	}
	return res;
}
void dfs(int step, int last, int score) {
	if (step > n) {
		ans = max(ans, score);
		return;
	}
	for (int i = 0; i < (1 << m); ++i) {
		if (check_line(i))
			if (check_next_line(i, last)) {
				dfs(step + 1, i, score + tot(i, step));
			}
	}
	return;
}
int main() {
	freopen("number.in", "r", stdin);
	freopen("number.out", "w", stdout);
	scanf("%d", &t);
	while (t--) {
		ans = 0;
		scanf("%d%d", &n, &m);
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				scanf("%d", &map[i][j]);
			}
		}
		dfs(1, 0, 0);
		printf("%d\n", ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}